<?php
require_once( "DBFunctions.php" );
require_once( "GXMLParser.php" );

class SProcCalls {
	function displayRegionsProjectDemo() {
		$db = new DBFunctions;
		$db->connectDB();
		$result = $db->query("call displayRegionsProjectDemo();");
		if( !$result ) {
			die( "Failed stored procedure call (displayRegionsProjectDemo)" );
		}
		
		$xml = new GXMLParser;
		$xml->openXML();
		while( $line = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) {
			$xml->addRegionFlag( $line['Name']  );
		}
		$xml->closeXMLWithTags();
		$db->closeDB();
	}
	
	function displayPopulationProjectDemo( $sid, $uid ) {
		$db = new DBFunctions;
		$db->connectDB();
		$result = $db->query("call displayPopulationProjectDemo(".$sid.",".$uid.");");
		if( !$result ) {
			die( "Failed stored procedure call (displayPopulationProjectDemo)" );
		}
		
		$xml = new GXMLParser;
		$xml->openXML();
		while( $line = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) {
			$xml->addSpeciesFlag( $line['Name'], $line['Population']  );
		}
		$xml->closeXML();
		$db->closeDB();
	}
	
	function displayPopulationProjectDemoWithTags( $sid, $uid ) {
		$db = new DBFunctions;
		$db->connectDB();
		$result = $db->query("call displayPopulationProjectDemo(".$sid.",".$uid.");");
		if( !$result ) {
			die( "Failed stored procedure call (displayPopulationProjectDemo)" );
		}
		
		$xml = new GXMLParser;
		$xml->openXML();
		while( $line = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) {
			$xml->addSpeciesFlag( $line['Name'], $line['Population']  );
		}
		$xml->closeXMLWithTags();
		$db->closeDB();
	}
	
	function decrementTimeOnEvents( $uid ) {
		$db = new DBFunctions;
		$db->connectDB();
		$result = $db->query("call decrementTimeOnEvents(".$uid.");");
		if( !$result ) {
			die( "Failed stored procedure call (displayPopulationProjectDemo)" );
		}
	}
	
	function addSpeciesToRegionProjectDemo( $sid, $rid, $uid, $population) {
		$db = new DBFunctions;
		$db->connectDB();
		$result = $db->query("call addSpeciesToRegionProjectDemo(".$sid.", ".$rid.", ".$uid.", ".$population.");");
		if( !$result ) {
			die( "Failed stored procedure call (displayPopulationProjectDemo)" );
		}
	}
}
?>